home *** CD-ROM | disk | FTP | other *** search
- unit WideLabel;
-
- interface
-
- // TWideLabel: just like TLabel, but supports wide strings.
- // Copyright ⌐ 2000 Tempest Software, Inc.
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TWideLabel = class(TLabel)
- private
- fWideCaption: WideString;
- procedure SetWideCaption(const Value: WideString);
- procedure ReadCaption(Reader: TReader);
- procedure WriteCaption(Writer: TWriter);
- protected
- procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
- procedure DefineProperties(Filer: TFiler); override;
- published
- property Caption: WideString read fWideCaption write SetWideCaption stored False;
- end;
-
- implementation
-
- { TWideLabel }
-
- // Delphi stores a WideString by converting it to a narrow string,
- // which discards information. Store the actual WideString data.
- procedure TWideLabel.DefineProperties(Filer: TFiler);
- begin
- inherited;
- Filer.DefineProperty('WideCaption', ReadCaption, WriteCaption, Caption <> '');
- end;
-
- // Copied from TLabel.DoDrawText, but changed to use DrawTextW
- // insted of DrawText (which is DrawTextA).
- procedure TWideLabel.DoDrawText(var Rect: TRect; Flags: Integer);
- var
- Text: WideString;
- begin
- Text := Caption;
- if (Flags and DT_CALCRECT <> 0) and
- ((Text = '') or
- ShowAccelChar and (Text[1] = '&') and (Text[2] = #0))
- then
- Text := Text + ' ';
-
- if not ShowAccelChar then
- Flags := Flags or DT_NOPREFIX;
- Flags := DrawTextBiDiModeFlags(Flags);
- Canvas.Font := Font;
-
- if not Enabled then
- begin
- OffsetRect(Rect, 1, 1);
- Canvas.Font.Color := clBtnHighlight;
- DrawTextW(Canvas.Handle, PWideChar(Text), Length(Text), Rect, Flags);
- OffsetRect(Rect, -1, -1);
- Canvas.Font.Color := clBtnShadow;
- DrawTextW(Canvas.Handle, PWideChar(Text), Length(Text), Rect, Flags);
- end
- else
- DrawTextW(Canvas.Handle, PWideChar(Text), Length(Text), Rect, Flags);
- end;
-
- // Read the real caption from the DFM.
- procedure TWideLabel.ReadCaption(Reader: TReader);
- begin
- fWideCaption := Reader.ReadWideString;
- end;
-
- // Store a new caption and redraw the control.
- procedure TWideLabel.SetWideCaption(const Value: WideString);
- begin
- fWideCaption := Value;
- AdjustBounds;
- Invalidate;
- end;
-
- // Write the real caption to the DFM.
- procedure TWideLabel.WriteCaption(Writer: TWriter);
- begin
- Writer.WriteWideString(Caption);
- end;
-
- end.
-